package com.snj.twelve;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

public class FileCopier {

    public static void main(String[] args) {
        // 源文件路径
        String sourceFilePath = "D:\\0_莘纳吉\\合同\\物资分组数据比对测试.xlsx";
        // 目标文件夹路径
        String destDirectory = "D:\\0_莘纳吉\\合同\\复制文件";

        try {
            copyFile(sourceFilePath, destDirectory);
            System.out.println("文件复制成功！");
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("文件复制失败！");
        }
    }

    public static void copyFile(String sourceFilePath, String destDirectory) throws IOException {
        // 创建源文件和目标文件夹路径对象
        Path sourcePath = Paths.get(sourceFilePath);
        Path destDirPath = Paths.get(destDirectory);

        // 确保目标文件夹存在
        if (!Files.exists(destDirPath)) {
            Files.createDirectories(destDirPath);
        }

        // 复制文件
        Path destFilePath = destDirPath.resolve(sourcePath.getFileName());
        Files.copy(sourcePath, destFilePath, StandardCopyOption.REPLACE_EXISTING);
    }
}